# -*- Mode: Python -*-
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
#   Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Jason Orendorff <jorendorff@mozilla.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

name = 'DOM'

# A quick warning:
#
# Attributes or methods that call GetCurrentNativeCallContext must not be
# quick-stubbed, because quick stubs don't generate a native call context.
# qsgen.py has no way of knowing which attributes and methods do this, as it
# looks at interfaces, not implementations.  The symptoms, if you quick-stub
# one of those, can be really weird, because GetCurrentNativeCallContext
# doesn't crash--it may in fact return a plausible wrong answer.

members = [ 
    # dom/interfaces/base
    #
    # Note that many implementations of interfaces in this directory
    # use GetCurrentNativeCallContext, notably:
    #   - nsIDOMCrypto.{generateCRMFRequest,signText}
    #   - nsIDOMLocation.reload
    #   - nsIDOMNSHistory.go
    #   - nsIDOMJSPluginArray.refresh
    #   - nsIDOMWindowInternal.postMessage
    #   - nsIDOMJSWindow.{prompt,setTimeout,setInterval,open,openDialog}
    #
    # (And nsIDOMModalContentWindow.returnValue is an attribute of type
    # nsIVariant, which qsgen.py can't handle.)
    #
    'nsIDOMWindow.name',
    'nsIDOMWindow.parent',
    'nsIDOMWindow.top',
    # Several window properties are magically resolved, including
    # location, _content, navigator, document, and window itself.
    # These do not need quick stubs.
    #'nsIDOMWindow.document',
    'nsIDOMWindow.getSelection',
    'nsIDOMWindow.scrollByLines',
    'nsIDOMJSWindow.dump',
    'nsIDOMScreen.top',
    'nsIDOMScreen.height',
    'nsIDOMScreen.width',
    'nsIDOMScreen.left',
    'nsIDOMClientRect.*',
    'nsIDOMClientRectList.*',
    'nsIDOMPaintRequest.*',
    'nsIDOMPaintRequestList.*',
    # nsLocationSH has ~ALLOW_PROP_MODS_TO_PROTOTYPE, so don't try.
    #'nsIDOMLocation.hostname',
    #'nsIDOMLocation.href',

    # dom/interfaces/canvas
    #
    # nsIDOMCanvasRenderingContext2D and friends
    'nsIDOMCanvasRenderingContext2D.*',
    'nsIDOMTextMetrics.*',
    'nsIDOMCanvasGradient.*',
    'nsIDOMCanvasPattern.*',

    # dom/interfaces/core
    'nsIDOMCharacterData.data',
    'nsIDOMCharacterData.length',
    'nsIDOMDocument.documentElement',
    'nsIDOMDocument.implementation',
    'nsIDOMDocument.getElementsByTagName',
    'nsIDOMDocument.doctype',
    'nsIDOMDocument.getElementsByTagNameNS',
    'nsIDOMDocument.getElementById',
    'nsIDOMDocument.createDocumentFragment',
    'nsIDOMDocument.createElement',
    'nsIDOMDocument.importNode',
    'nsIDOMDocument.createTextNode',
    'nsIDOMElement.removeAttributeNS',
    'nsIDOMElement.removeAttribute',
    'nsIDOMElement.getAttribute',
    'nsIDOMElement.getElementsByTagName',
    'nsIDOMElement.setAttribute',
    'nsIDOMElement.getElementsByTagNameNS',
    'nsIDOMElement.hasAttributeNS',
    'nsIDOMElement.tagName',
    'nsIDOMElement.setAttributeNS',
    'nsIDOMElement.hasAttribute',
    'nsIDOMElement.getAttributeNS',
    'nsIDOMNamedNodeMap.item',
    'nsIDOMNamedNodeMap.length',
    'nsIDOMNode.appendChild',
    'nsIDOMNode.nextSibling',
    'nsIDOMNode.cloneNode',
    'nsIDOMNode.firstChild',
    'nsIDOMNode.prefix',
    'nsIDOMNode.nodeValue',
    'nsIDOMNode.childNodes',
    'nsIDOMNode.normalize',
    'nsIDOMNode.nodeName',
    'nsIDOMNode.namespaceURI',
    'nsIDOMNode.hasChildNodes',
    'nsIDOMNode.previousSibling',
    'nsIDOMNode.nodeType',
    'nsIDOMNode.insertBefore',
    'nsIDOMNode.replaceChild',
    'nsIDOMNode.localName',
    'nsIDOMNode.lastChild',
    'nsIDOMNode.ownerDocument',
    'nsIDOMNode.parentNode',
    'nsIDOMNode.removeChild',
    'nsIDOMNode.hasAttributes',
    'nsIDOMNode.attributes',
    'nsIDOMNodeList.*',
    'nsIDOMNodeSelector.querySelector',
    'nsIDOMNodeSelector.querySelectorAll',
    'nsIDOMText.splitText',
    'nsIDOM3Document.documentURI',
    'nsIDOM3Document.adoptNode',
    'nsIDOM3Document.renameNode',
    'nsIDOM3Node.*',
    'nsIDOMDOMImplementation.*',
    'nsIDOMDOMStringList.*',
    'nsIDOMDOMTokenList.*',
    'nsIDOMDOMSettableTokenList.*',
    'nsIDOMNameList.getName',
    'nsIDOMNameList.contains',
    'nsIDOMNameList.containsNS',
    'nsIDOMNameList.length',
    'nsIDOMNameList.getNamespaceURI',
    'nsIDOMNSDocument.getElementsByClassName',
    'nsIDOMNSDocument.title',
    'nsIDOMNSDocument.hasFocus',
    # This property is treated specially in nsDOMClassInfo in a way that
    # would shadow any quick stub.  Also, document.location is a special
    # case for security.
    #'nsIDOMNSDocument.location',
    'nsIDOMNSDocument.elementFromPoint',
    'nsIDOMNSDocument.activeElement',
    'nsIDOMXULDocument.getBoxObjectFor',
    'nsIDOMXMLDocument.evaluateXPointer',
    'nsIDOMXMLDocument.evaluateFIXptr',
    'nsIDOMNSElement.*',

    # dom/interfaces/css
    'nsIDOMElementCSSInlineStyle.*',
    'nsIDOMCSS2Properties.*',
    'nsIDOMRect.*',
    'nsIDOMViewCSS.getComputedStyle',
    'nsIDOMCSSStyleDeclaration.*',

    # dom/interfaces/events
    'nsIDOMEventTarget.dispatchEvent',
    'nsIDOMEventTarget.removeEventListener',
    'nsIDOMNSEventTarget.addEventListener',
    'nsIDOMDocumentEvent.*',

    'nsIDOMEvent.*',
    'nsIDOMMouseEvent.*',
    'nsIDOMKeyEvent.*',
    'nsIDOMMutationEvent.*',
    'nsIDOMDragEvent.*',
    'nsIDOMScrollAreaEvent.*',
    'nsIDOMNotifyPaintEvent.*',
    'nsIDOMMessageEvent.*',
    'nsIDOMMouseScrollEvent.*',
    'nsIDOMProgressEvent.lengthComputable',
    'nsIDOMProgressEvent.loaded',
    'nsIDOMProgressEvent.total',
    #XXX Can't quickstub initProgressEvent because it has long long parameters.
    'nsIDOMNSEvent.originalTarget',
    'nsIDOMNSEvent.getPreventDefault',
    'nsIDOMNSUIEvent.which',
    'nsIDOMNSUIEvent.rangeParent',
    'nsIDOMNSUIEvent.rangeOffset',
    'nsIDOMNSUIEvent.pageX',
    'nsIDOMNSUIEvent.pageY',
    'nsIDOMNSUIEvent.isChar',

    # dom/interfaces/geolocation - None.

    # dom/interfaces/html
    'nsIDOMHTMLAnchorElement.href',
    'nsIDOMHTMLAnchorElement.rel',
    'nsIDOMHTMLAnchorElement.target',
    'nsIDOMHTMLAnchorElement.name',
    'nsIDOMHTMLAnchorElement.text',
    'nsIDOMHTMLAnchorElement.search',
    'nsIDOMHTMLAnchorElement.hash',
    'nsIDOMHTMLBaseElement.href',
    'nsIDOMHTMLBaseElement.target',
    'nsIDOMHTMLButtonElement.name',
    'nsIDOMHTMLButtonElement.form',
    'nsIDOMHTMLButtonElement.value',
    'nsIDOMHTMLButtonElement.disabled',
    'nsIDOMHTMLCollection.item',
    # This is shadowed by nsIDOMHTMLOptionsCollection.length,
    # but it is also present in other objects where it isn't shadowed.
    # Quick stubs handle the shadowing the same as XPConnect.
    'nsIDOMHTMLCollection.length',
    'nsIDOMHTMLDocument.body',
    'nsIDOMHTMLDocument.getElementsByName',
    'nsIDOMHTMLDocument.anchors',
    'nsIDOMHTMLDocument.links',
    'nsIDOMHTMLDocument.title',
    'nsIDOMHTMLDocument.URL',
    'nsIDOMHTMLDocument.referrer',
    'nsIDOMHTMLDocument.forms',
    'nsIDOMHTMLDocument.cookie',
    'nsIDOMHTMLDocument.images',
    'nsIDOMHTMLDocument.write',
    'nsIDOMHTMLDocument.writeln',
    'nsIDOMHTMLElement.*',
    'nsIDOMHTMLFormElement.elements',
    'nsIDOMHTMLFormElement.name',
    'nsIDOMHTMLFormElement.submit',
    'nsIDOMHTMLFormElement.length',
    'nsIDOMHTMLFormElement.target',
    'nsIDOMHTMLFormElement.action',
    'nsIDOMHTMLFrameElement.src',
    'nsIDOMHTMLFrameElement.contentDocument',
    'nsIDOMHTMLFrameElement.name',
    'nsIDOMHTMLFrameSetElement.rows',
    'nsIDOMHTMLFrameSetElement.cols',
    'nsIDOMHTMLIFrameElement.src',
    'nsIDOMHTMLIFrameElement.contentDocument',
    'nsIDOMHTMLImageElement.src',
    'nsIDOMHTMLImageElement.name',
    'nsIDOMHTMLImageElement.height',
    'nsIDOMHTMLImageElement.width',
    'nsIDOMHTMLImageElement.complete',
    'nsIDOMHTMLInputElement.defaultChecked',
    'nsIDOMHTMLInputElement.disabled',
    'nsIDOMHTMLInputElement.select',
    'nsIDOMHTMLInputElement.checked',
    'nsIDOMHTMLInputElement.type',
    'nsIDOMHTMLInputElement.form',
    'nsIDOMHTMLInputElement.src',
    'nsIDOMHTMLInputElement.name',
    'nsIDOMHTMLInputElement.value',
    'nsIDOMHTMLInputElement.files',
    'nsIDOMHTMLInputElement.textLength',
    'nsIDOMHTMLInputElement.selectionStart',
    'nsIDOMHTMLInputElement.selectionEnd',
    'nsIDOMHTMLInputElement.setSelectionRange',
    'nsIDOMHTMLLinkElement.disabled',
    'nsIDOMHTMLOptionElement.index',
    'nsIDOMHTMLOptionElement.selected',
    'nsIDOMHTMLOptionElement.form',
    'nsIDOMHTMLOptionElement.text',
    'nsIDOMHTMLOptionElement.defaultSelected',
    'nsIDOMHTMLOptionElement.value',
    'nsIDOMHTMLOptionElement.label',
    'nsIDOMHTMLOptionElement.disabled',
    'nsIDOMHTMLOptionsCollection.item',
    'nsIDOMHTMLOptionsCollection.length',
    'nsIDOMHTMLSelectElement.name',
    'nsIDOMHTMLSelectElement.form',
    'nsIDOMHTMLSelectElement.add',
    'nsIDOMHTMLSelectElement.value',
    'nsIDOMHTMLSelectElement.disabled',
    'nsIDOMHTMLSelectElement.length',
    'nsIDOMHTMLSelectElement.remove',
    'nsIDOMHTMLSelectElement.selectedIndex',
    'nsIDOMHTMLSelectElement.item',
    'nsIDOMHTMLSelectElement.type',
    'nsIDOMHTMLSelectElement.options',
    'nsIDOMHTMLSelectElement.size',
    'nsIDOMHTMLStyleElement.disabled',
    'nsIDOMHTMLTableCellElement.colSpan',
    'nsIDOMHTMLTableCellElement.headers',
    'nsIDOMHTMLTableCellElement.cellIndex',
    'nsIDOMHTMLTableCellElement.rowSpan',
    'nsIDOMHTMLTableCellElement.abbr',
    'nsIDOMHTMLTableCellElement.scope',
    'nsIDOMHTMLTableCellElement.noWrap',
    'nsIDOMHTMLTableCellElement.width',
    'nsIDOMHTMLTableColElement.span',
    'nsIDOMHTMLTableColElement.width',
    'nsIDOMHTMLTableElement.rows',
    'nsIDOMHTMLTableElement.deleteRow',
    'nsIDOMHTMLTableElement.summary',
    'nsIDOMHTMLTableElement.insertRow',
    'nsIDOMHTMLTableRowElement.sectionRowIndex',
    'nsIDOMHTMLTableRowElement.rowIndex',
    'nsIDOMHTMLTableRowElement.cells',
    'nsIDOMHTMLTableRowElement.deleteCell',
    'nsIDOMHTMLTableRowElement.insertCell',
    'nsIDOMHTMLTableSectionElement.rows',
    'nsIDOMHTMLTableSectionElement.insertRow',
    'nsIDOMHTMLTableSectionElement.deleteRow',
    'nsIDOMHTMLTextAreaElement.rows',
    'nsIDOMHTMLTextAreaElement.name',
    'nsIDOMHTMLTextAreaElement.form',
    'nsIDOMHTMLTextAreaElement.defaultValue',
    'nsIDOMHTMLTextAreaElement.cols',
    'nsIDOMHTMLTextAreaElement.value',
    'nsIDOMHTMLTextAreaElement.type',
    'nsIDOMHTMLTextAreaElement.select',
    'nsIDOMHTMLTitleElement.text',
    'nsIDOMHTMLCanvasElement.width',
    'nsIDOMHTMLCanvasElement.height',
    'nsIDOMHTMLCanvasElement.getContext',
    'nsIDOMHTMLCanvasElement.toDataURL',
    'nsIDOMNSHTMLDocument.width',
    'nsIDOMNSHTMLDocument.height',
    'nsIDOMNSHTMLDocument.domain',
    'nsIDOMNSHTMLDocument.getSelection',
    'nsIDOMNSHTMLDocument.designMode',
    'nsIDOMNSHTMLElement.contentEditable',
    'nsIDOMNSHTMLElement.isContentEditable',
    'nsIDOMNSHTMLElement.offsetParent',
    'nsIDOMNSHTMLElement.innerHTML',
    'nsIDOMNSHTMLElement.offsetLeft',
    'nsIDOMNSHTMLElement.offsetTop',
    'nsIDOMNSHTMLElement.offsetHeight',
    'nsIDOMNSHTMLElement.offsetWidth',
    'nsIDOMNSHTMLElement.scrollIntoView',
    'nsIDOMNSHTMLFrameElement.contentWindow',
    'nsIDOMNSHTMLOptionCollection.selectedIndex',
    'nsIDOMNSHTMLOptionCollection.add',
    'nsIDOMNSHTMLTextAreaElement.setSelectionRange',
    'nsIDOMNSHTMLTextAreaElement.selectionStart',
    'nsIDOMNSHTMLTextAreaElement.selectionEnd',
    'nsIDOMNSHTMLTextAreaElement.textLength',
    'nsIDOMNSHTMLTextAreaElement.wrap',

    # dom/interfaces/json - None.
    # All 4 methods of nsIJSON call GetCurrentNativeCallContext.

    # dom/interfaces/load-save - None.

    # dom/interfaces/offline - None.

    # dom/interfaces/range
    'nsIDOMRange.*',

    # dom/interfaces/sidebar - None.

    # dom/interfaces/smil - None.

    # dom/interfaces/storage
    'nsIDOMToString.toString',
    'nsIDOMStorage.setItem',
    'nsIDOMStorage.length',
    'nsIDOMStorage.getItem',
    'nsIDOMStorage.key',
    'nsIDOMStorage.removeItem',
    'nsIDOMStorage.clear',
    'nsIDOMStorageItem.value',
    'nsIDOMStorageWindow.*',

    # dom/interfaces/stylesheets - None.

    # dom/interfaces/svg - None.
    'nsIDOMSVGStylable.*',

    # dom/interfaces/threads - None.

    # dom/interfaces/traversal
    'nsIDOMDocumentTraversal.createNodeIterator',
    'nsIDOMNodeIterator.nextNode',

    # dom/interfaces/views
    'nsIDOMDocumentView.defaultView',

    # dom/interfaces/xbl - None.

    # dom/interfaces/xpath
    'nsIDOMXPathEvaluator.evaluate',
    'nsIDOMXPathEvaluator.createExpression',
    'nsIDOMXPathEvaluator.createNSResolver',
    'nsIDOMXPathExpression.evaluate',
    'nsIDOMXPathNSResolver.lookupNamespaceURI',
    'nsIDOMXPathResult.snapshotItem',
    'nsIDOMXPathResult.iterateNext',
    'nsIDOMXPathResult.snapshotLength',
    'nsIDOMXPathResult.resultType',
    'nsIDOMXPathResult.numberValue',
    'nsIDOMXPathResult.stringValue',
    'nsIDOMXPathResult.booleanValue',
    'nsIDOMXPathResult.singleNodeValue',
    'nsIDOMNSXPathExpression.evaluateWithContext',

    # dom/interfaces/xul - None.

    # XHR
    'nsIXMLHttpRequest.*',
    # nsIXMLHttpRequest.channel is not used on the web, and more
    # importantly relies on the CAPS check that quickstubs don't make.
    '-nsIXMLHttpRequest.channel',
    # nsIXMLHttpRequest.open uses the JS stack
    '-nsIXMLHttpRequest.open',
    # various XHR things use ACString and AUTF8String and [cstring]
    # which quickstubs don't handle as return values (or at all in the
    # case of AUTF8String) yet.
    '-nsIXMLHttpRequest.statusText',
    '-nsIXMLHttpRequest.getAllResponseHeaders',
    '-nsIXMLHttpRequest.getResponseHeader',
    '-nsIXMLHttpRequest.setRequestHeader',
    '-nsIXMLHttpRequest.overrideMimeType',
    # nsIXMLHttpRequestUpload doesn't live in its own IDL file, so
    # can't be quickstubbed
    '-nsIXMLHttpRequest.upload',

    # WebSocket
    'nsIWebSocket.*',

    # webgl
    'nsICanvasRenderingContextWebGL.*',
    # These all use GetCurrentNativeCallContext and should be
    # custom-quickstubbed.
    '-nsICanvasRenderingContextWebGL.getActiveAttrib',
    '-nsICanvasRenderingContextWebGL.getActiveUniform',
    '-nsICanvasRenderingContextWebGL.getParameter',
    '-nsICanvasRenderingContextWebGL.getBufferParameter',
    '-nsICanvasRenderingContextWebGL.getFramebufferAttachmentParameter',
    '-nsICanvasRenderingContextWebGL.getRenderbufferParameter',
    '-nsICanvasRenderingContextWebGL.getProgramParameter',
    '-nsICanvasRenderingContextWebGL.getUniform',
    '-nsICanvasRenderingContextWebGL.getVertexAttrib',
    '-nsICanvasRenderingContextWebGL.getShaderParameter',

    # Audio
    'nsIDOMNotifyAudioAvailableEvent.frameBuffer',
    'nsIDOMNotifyAudioAvailableEvent.time',
    'nsIDOMHTMLAudioElement.mozWriteAudio',

    # dom/indexedDB
    'nsIIDBCursor.*',
    'nsIIDBDatabase.*',
    'nsIIDBDatabaseException.*',
    'nsIIDBEvent.*',
    'nsIIDBErrorEvent.*',
    'nsIIDBIndex.*',
    'nsIIDBKeyRange.*',
    'nsIIDBObjectStore.*',
    'nsIIDBRequest.*',
    'nsIIDBSuccessEvent.*',
    'nsIIDBTransaction.*',
    'nsIIDBTransactionEvent.*',
    'nsIIDBFactory.*',
    ]

# Most interfaces can be found by searching the includePath; to find
# nsIDOMEvent, for example, just look for nsIDOMEvent.idl.  But IDL filenames
# for very long interface names are slightly abbreviated, and many interfaces
# don't have their own files, just for extra wackiness.  So qsgen.py needs
# a little help.
#
irregularFilenames = {
    # abbreviations
    'nsIDOMNSHTMLOptionCollection': 'nsIDOMNSHTMLOptionCollectn',
    'nsIDOMHTMLTableSectionElement': 'nsIDOMHTMLTableSectionElem',

    # stowaways
    'nsIDOMTextMetrics': 'nsIDOMCanvasRenderingContext2D',
    'nsIDOMCanvasGradient': 'nsIDOMCanvasRenderingContext2D',
    'nsIDOMCanvasPattern': 'nsIDOMCanvasRenderingContext2D',
    'nsIXPointerResult': 'nsIXPointer',

    'nsIWebGLTexture': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLBuffer': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLProgram': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLShader': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLShaderArray': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLFramebuffer': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLRenderbuffer': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLActiveInfo': 'nsICanvasRenderingContextWebGL',
    'nsIWebGLUniformLocation': 'nsICanvasRenderingContextWebGL',
    }

customIncludes = [
    'nsINode.h',
    'nsIContent.h',
    'nsIDocument.h',
    'nsINodeList.h',
    'nsCSSPropertiesQS.h',
    'nsDocument.h',
    'nsGenericDOMDataNode.h',
    'nsGenericElement.h',
    'nsGenericHTMLElement.h',
    'nsSVGStylableElement.h',
    'nsHTMLDocument.h',
    'nsDOMQS.h',
    ]

customQuickStubs = [
    'CustomQS_WebGL.h',
    'CustomQS_Canvas2D.h'
    ]

customReturnInterfaces = [
    'nsIDOMCanvasPattern',
    'nsIDOMCanvasGradient',
    ]

nsIDOMNode_GetChildNodes_customMethodCallCode = """
    nsIDOMNodeList* result = self->GetChildNodesList();
    rv = result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
"""

nsIDOMHTMLDocument_Write_customMethodCallCode = """
    nsAString &str = arg0;
    for (uintN i = 1; i < argc; ++i) {
      xpc_qsDOMString next_arg(cx, argv[i], &argv[i],
                               xpc_qsDOMString::eStringify,
                               xpc_qsDOMString::eStringify);
      if (!next_arg.IsValid())
        return JS_FALSE;

      str.Append(next_arg);
    }

    rv = self->%s(arg0);
"""

nsIDOMStorage_Clear_customMethodCallCode = """
    rv = self->Clear();
    if (NS_SUCCEEDED(rv))
        JS_ClearScope(cx, obj);
"""

CUSTOM_QS = {
    'skipgen': True,
    'traceable': False
}

CUSTOM_QS_TN = {
    'skipgen': True,
    'traceable': True
}

customMethodCalls = {
    'nsIDOMNode_GetNextSibling': {
        'thisType': 'nsINode',
        'code': '    nsINode *result = self->GetNextSibling();',
        'canFail': False
        },
    'nsIDOMNode_GetFirstChild': {
        'thisType': 'nsINode',
        'code': '    nsINode *result = self->GetFirstChild();',
        'canFail': False
        },
    'nsIDOMNode_GetChildNodes': {
        'thisType': 'nsINode',
        'code': nsIDOMNode_GetChildNodes_customMethodCallCode
        },
    'nsIDOMNode_GetPreviousSibling': {
        'thisType': 'nsINode',
        'code': '    nsINode *result = self->GetPreviousSibling();',
        'canFail': False
        },
    'nsIDOMNode_GetLastChild': {
        'thisType': 'nsINode',
        'code': '    nsINode *result = self->GetLastChild();',
        'canFail': False
        },
    'nsIDOMNode_GetOwnerDocument': {
        'thisType': 'nsINode',
        'code': '    nsIDocument *result = self->GetOwnerDocument();',
        'canFail': False
        },
    'nsIDOMNode_GetParentNode': {
        'thisType': 'nsINode',
        'code': '    nsINode *result = self->GetNodeParent();',
        'canFail': False
        },
    'nsIDOMNode_InsertBefore': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode',
        'arg1Type': 'nsINode',
        'code': '    nsINode *result = self->InsertBefore(arg0, arg1, &rv);\n'
                '    if(NS_FAILED(rv))\n'
                '        result = nsnull;'
        },
    'nsIDOMNode_ReplaceChild': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode',
        'arg1Type': 'nsINode',
        'code': '    nsINode *result = self->ReplaceChild(arg0, arg1, &rv);\n'
                '    if(NS_FAILED(rv))\n'
                '        result = nsnull;'
        },
    'nsIDOMNode_RemoveChild': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode',
        'code': '    rv = self->RemoveChild(arg0);\n'
                '    nsINode *result = NS_SUCCEEDED(rv) ? arg0 : nsnull;'
        },
    'nsIDOMNode_AppendChild': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode',
        'code': '    nsINode *result = self->AppendChild(arg0, &rv);\n'
                '    if(NS_FAILED(rv))\n'
                '        result = nsnull;'
        },
    'nsIDOMNode_GetNodeType': {
        'thisType': 'nsINode',
        'canFail': False
        },
    'nsIDOMNodeList_Item': {
        'thisType': 'nsINodeList',
        'code': '    nsINode *result = self->GetNodeAt(arg0);',
        'canFail': False
        },
    'nsIDOMHTMLDocument_': {
        'thisType': 'nsHTMLDocument'
        },
    'nsIDOMNodeList_GetLength': {
        'thisType': 'nsINodeList'
        },
    'nsIDOMHTMLDocument_Write': {
        'thisType': 'nsHTMLDocument',
        'code': nsIDOMHTMLDocument_Write_customMethodCallCode % 'Write'
        },
    'nsIDOMHTMLDocument_Writeln': {
        'thisType': 'nsHTMLDocument',
        'code': nsIDOMHTMLDocument_Write_customMethodCallCode % 'Writeln'
        },
    'nsIDOMHTMLDocument_GetBody': {
        'thisType': 'nsHTMLDocument',
        'code': '    nsIContent *result = self->GetBody(&rv);'
        },
    'nsIDOMHTMLDocument_GetElementsByName': {
        'thisType': 'nsHTMLDocument',
        'code': '    nsRefPtr<nsContentList> result = '
                'self->GetElementsByName(arg0);',
        'canFail': False
        },
    'nsIDOMNSHTMLDocument_': {
        'thisType': 'nsHTMLDocument'
        },
    'nsIDOMStorage_Clear': {
        'code': nsIDOMStorage_Clear_customMethodCallCode
        },
    'nsIDOMCanvasRenderingContext2D_StrokeStyle': { 'skipgen': True },
    'nsIDOMCanvasRenderingContext2D_StrokeStyle': { 'skipgen': True },
    'nsIDOMCanvasRenderingContext2D_FillStyle': { 'skipgen': True },
    'nsIDOMCanvasRenderingContext2D_FillStyle': { 'skipgen': True },
    'nsIDOMCSS2Properties_': {
        'thisType': 'nsICSSDeclaration',
        'additionalArguments': 'const nsCSSProperty prop',
        'additionalArgumentValues': 'QS_CSS_PROP_%s',
        'getter_code': '    nsString result;\n' + 
                       '    rv = self->GetPropertyValue(prop, result);',
        'setter_code': '    rv = self->SetPropertyValue(prop, arg0);',
        'canFail': True
        },
    'nsIDOMNSElement_': {
        'thisType': 'nsGenericElement'
        },
    'nsIDOMNSElement_GetScrollTop': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetScrollTop();',
        'canFail': False
        },
    'nsIDOMNSElement_SetScrollTop': {
        'thisType': 'nsGenericElement',
        'canFail': False
        },
    'nsIDOMNSElement_GetScrollLeft': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetScrollLeft();',
        'canFail': False
        },
    'nsIDOMNSElement_SetScrollLeft': {
        'thisType': 'nsGenericElement',
        'canFail': False
        },
    'nsIDOMNSElement_GetScrollHeight': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetScrollHeight();',
        'canFail': False
        },
    'nsIDOMNSElement_GetScrollWidth': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetScrollWidth();',
        'canFail': False
        },
    'nsIDOMNSElement_GetClientTop': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetClientTop();',
        'canFail': False
        },
    'nsIDOMNSElement_SetClientTop': {
        'thisType': 'nsGenericElement',
        'canFail': False
        },
    'nsIDOMNSElement_GetClientLeft': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetClientLeft();',
        'canFail': False
        },
    'nsIDOMNSElement_SetClientLeft': {
        'thisType': 'nsGenericElement',
        'canFail': False
        },
    'nsIDOMNSElement_GetClientHeight': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetClientHeight();',
        'canFail': False
        },
    'nsIDOMNSElement_GetClientWidth': {
        'thisType': 'nsGenericElement',
        'code': '    PRInt32 result = self->GetClientWidth();',
        'canFail': False
        },
    'nsIDOMNSElement_GetFirstElementChild': {
        'thisType': 'nsGenericElement',
        'code': '    nsIContent *result = self->GetFirstElementChild();',
        'canFail': False
        },
    'nsIDOMNSElement_GetLastElementChild': {
        'thisType': 'nsGenericElement',
        'code': '    nsIContent *result = self->GetLastElementChild();',
        'canFail': False
        },
    'nsIDOMNSElement_GetPreviousElementSibling': {
        'thisType': 'nsGenericElement',
        'code': '    nsIContent *result = self->GetPreviousElementSibling();',
        'canFail': False
        },
    'nsIDOMNSElement_GetNextElementSibling': {
        'thisType': 'nsGenericElement',
        'code': '    nsIContent *result = self->GetNextElementSibling();',
        'canFail': False
        },
    'nsIDOMNSElement_GetClassList': {
        'thisType': 'nsGenericElement',
        'code': '    nsIDOMDOMTokenList *result = self->GetClassList(&rv);'
        },
    'nsIDOMNSElement_SetCapture': {
        'thisType': 'nsGenericElement',
        'canFail': False
        },
    'nsIDOMNSElement_ReleaseCapture': {
        'thisType': 'nsGenericElement',
        'canFail': False
        },
    'nsIDOMNSElement_MozMatchesSelector': {
        'thisType': 'nsGenericElement',
        'code': '    PRBool result = self->MozMatchesSelector(arg0);',
        'canFail': False
        },
    'nsIDOM3Text_': {
        'thisType': 'nsGenericTextNode'
        },
    'nsIDOM3Text_IsElementContentWhitespace': {
        'thisType': 'nsGenericTextNode',
        'code': '    PRBool result = self->IsElementContentWhitespace();',
        'canFail': False
        },
    'nsIDOM3Text_ReplaceWholeText': {
        'thisType': 'nsGenericTextNode',
        'code': '    nsIContent* result = '
                'self->ReplaceWholeText(PromiseFlatString(arg0), &rv);'
        },
    'nsIDOMNodeSelector_QuerySelector': {
        'thisType': 'nsINode',
        'code': '    nsIContent* result = '
                'nsGenericElement::doQuerySelector(self, arg0, &rv);'
        },
    'nsIDOMNodeSelector_QuerySelectorAll': {
        'thisType': 'nsINode',
        'code': '    nsCOMPtr<nsIDOMNodeList> result;\n'
                '    rv = nsGenericElement::doQuerySelectorAll(self, '
                'arg0, getter_AddRefs(result));'
        },
    'nsIDOM3Node_': {
        'thisType': 'nsINode'
        },
    'nsIDOM3Node_GetBaseURI': {
        'thisType': 'nsINode',
        'canFail': False
        },
    'nsIDOM3Node_CompareDocumentPosition': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode'
        },
    'nsIDOM3Node_GetTextContent': {
        'thisType': 'nsINode',
        'canFail': False
        },
    'nsIDOM3Node_IsSameNode': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode',
        'code': '    PRBool result = self->IsSameNode(arg0);',
        'canFail': False
        },
    'nsIDOM3Node_LookupPrefix': {
        'thisType': 'nsINode',
        'canFail': False
        },
    'nsIDOM3Node_IsDefaultNamespace': {
        'thisType': 'nsINode',
        'code': '    PRBool result = self->IsDefaultNamespace(arg0);',
        'canFail': False
        },
    'nsIDOM3Node_LookupNamespaceURI': {
        'thisType': 'nsINode',
        'canFail': False
        },
    'nsIDOM3Node_IsEqualNode': {
        'thisType': 'nsINode',
        'arg0Type': 'nsINode',
        'code': '    PRBool result = self->IsEqualNode(arg0);',
        'canFail': False
        },
    'nsIDOM3Node_GetUserData': {
        'thisType': 'nsINode',
        'code': '    nsIVariant *result = self->GetUserData(arg0);',
        'canFail': False
        },
    'nsIDOMNSHTMLElement_': {
        'thisType': 'nsGenericHTMLElement'
        },
    'nsIDOMHTMLElement_': {
        'thisType': 'nsGenericHTMLElement'
        },
    'nsIDOMElementCSSInlineStyle_': {
        'thisType': 'nsStyledElement'
        },
    'nsIDOMElementCSSInlineStyle_GetStyle': {
        'thisType': 'nsStyledElement',
        'code': '    nsIDOMCSSStyleDeclaration* result = '
                'self->GetStyle(&rv);'
        },
    'nsIDOMSVGStylable_GetStyle': {
        'thisType': 'nsSVGStylableElement',
        'code': '    nsIDOMCSSStyleDeclaration* result = '
                'self->GetStyle(&rv);'
        },
    'nsIDOMDocument_': {
        'thisType': 'nsDocument'
        },
    'nsIDOMDocument_GetElementById': {
        'thisType': 'nsDocument',
        'code': '    mozilla::dom::Element *result = self->GetElementById(arg0);',
        'canFail': False
        },
    'nsIDOMDocument_GetElementsByTagName': {
        'thisType': 'nsDocument',
        'code': '    nsRefPtr<nsContentList> result ='
                'self->GetElementsByTagName(arg0);',
        'canFail': False
        },
    'nsIDOMDocument_GetElementsByTagNameNS': {
        'thisType': 'nsDocument',
        'code': '    nsRefPtr<nsContentList> result ='
                'self->GetElementsByTagNameNS(arg0, arg1);',
        'canFail': False
        },
    'nsIDOMNSDocument_': {
        'thisType': 'nsDocument'
        },
    'nsIDOM3Document_': {
        'thisType': 'nsDocument'
        },
    'nsIDOMElement_': {
        'thisType': 'nsGenericElement'
        },
    'nsIDOMDocument_CreateElement': {
        'thisType': 'nsDocument',
        'code': '    nsCOMPtr<nsIContent> result;\n'
                '    rv = self->CreateElement(arg0, getter_AddRefs(result));'
    },
    'nsIDOMDocument_CreateTextNode': {
        'thisType': 'nsDocument',
        'code': '    nsCOMPtr<nsIContent> result;\n'
                '    rv = self->CreateTextNode(arg0, getter_AddRefs(result));'
    },
    # WebGL
    'nsICanvasRenderingContextWebGL_BufferData': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_BufferSubData': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_ReadPixels': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_TexImage2D': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_TexSubImage2D': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_Uniform1iv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform2iv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform3iv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform4iv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform1fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform2fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform3fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_Uniform4fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_UniformMatrix2fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_UniformMatrix3fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_UniformMatrix4fv': CUSTOM_QS_TN,
    'nsICanvasRenderingContextWebGL_VertexAttrib1fv': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_VertexAttrib2fv': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_VertexAttrib3fv': CUSTOM_QS,
    'nsICanvasRenderingContextWebGL_VertexAttrib4fv': CUSTOM_QS,
    # Canvas 2D
    'nsIDOMCanvasRenderingContext2D_CreateImageData': CUSTOM_QS,
    'nsIDOMCanvasRenderingContext2D_GetImageData': CUSTOM_QS,
    'nsIDOMCanvasRenderingContext2D_PutImageData': CUSTOM_QS,
    }

